<template>
	<div id="Returnwork">
		<el-form ref="form" :model="form" label-width="180px" v-show="isShowForm==true">
			<el-form-item label="选择退回到的节点和人员">
				<el-select v-model="form.selectedNodeID">
					<el-option
						v-for="item in returnData"
						:key="item.No"
						:label="item.RecName + item.Name"
						:value="item.No+'@'+item.Rec"
					></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="退回原因">
				<el-input type="textarea" v-model="form.doc"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="onSubmit">确定返回</el-button>
				<el-button @click="onSubmit" v-show="isShowBackTracking==true">返回后并发送给我</el-button>
				<el-button @click="onSubmit" v-show="isShowKillEtcThread==true">全部子线程退回</el-button>
				<el-button>关闭</el-button>
			</el-form-item>
		</el-form>
		<div v-show="isShowDiv==true" v-html="msg"></div>
	</div>
</template>

<script>
export default {
	name: "Returnwork",
	data() {
		return {
			form: {
				selectedNodeID: "",
				doc: ""
			},
            returnData: [],
            isBack:false,
            params:{},
			isShowForm:true,//点击退回按钮直接退回时隐藏
			isShowBackTracking:false, //是否显示原路返回
			isShowKillEtcThread:false,//是否显示退回所有子线程

			isShowDiv:false,
			msg:""
		};
	},

	created() {
        this.params = this.$store.getters.getData;
        this.loadData();
	},
	methods: {
		loadData(){
			let handler = new this.HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
			handler.AddJson(this.params);
			//初始化数据.
			let data = handler.DoMethodReturnString("Return_Init");
			if (data.indexOf('info@') == 0) {
				data = data.replace("info@","");
				this.isShowDiv=true;
				this.isShowForm=false;
				this.msg = data;
				return;
			}
			if (data.indexOf('err@') == 0) {
				data = data.replace("err@","");
				this.isShowDiv=true;
				this.isShowForm=false;
				this.msg = data;
				//this.$message.error(data);
				return;
			}
			let node = this.Entity("BP.WF.Node",this.params.FK_Node);
			if(node.IsBackTracking == 1)
				this.isShowBackTracking = true;
			if(node.IsKillEtcThread==1)
				this.isShowKillEtcThread == true;
			this.returnData = JSON.parse(data);
		},
		onSubmit() {
			if (!this.form.selectedNodeID) {
				this.$message({
					message: "请选择要退回的节点",
					type: "warning"
                });
                return;
            }
            if (!this.form.doc) {
				this.$message({
					message: "请输入退回原因",
					type: "warning"
                });
                return;
            }

            this.params.ReturnToNode = this.form.selectedNodeID;
            this.params.ReturnInfo = this.form.doc;
            this.params.IsBack = this.isShowBackTracking
			this.params.IsKillEtcThread = this.isShowKillEtcThread;
            let handler = new this.HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddJson(this.params);
            //调用退回方法.
            let data = handler.DoMethodReturnString("DoReturnWork"); //执行方法.
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            this.$message({
                message: data,
                type: 'success'
            });

            this.$Bus.$emit("closeMsg","退回")
		}
	},

	//监听
	computed: {},

	components: {},

	//监听后执行动作
	watch: {}
};
</script>

<style lang="less" scoped>
</style>